package com.xgzit.xgzmall.order.web;

import com.alipay.api.AlipayApiException;
import com.xgzit.xgzmall.order.config.AlipayTemplate;
import com.xgzit.xgzmall.order.service.OrderService;
import com.xgzit.xgzmall.order.vo.PayVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @Author xgz
 * @Date 2021-07-09 22:16
 */
@Slf4j
@Controller
public class PayWebController {

    @Autowired
    AlipayTemplate alipayTemplate;

    @Autowired
    OrderService orderService;


    /**
     * 支付成功以后 我们要跳转到订单列表页面
     * */
    @ResponseBody
    @GetMapping(value = "/payOrder", produces = "text/html")
    public String payOrder(@RequestParam("orderSn") String orderSn) throws AlipayApiException {

        PayVo payVo = orderService.getOrderPay(orderSn);
        String pay = alipayTemplate.pay(payVo);
        log.info(pay);
        // 支付宝返回的是一个页面，将此页面直接交给浏览器就像
        return pay;
    }

}
